﻿<?xml version="1.0" encoding="utf-8"?>
<UserControl
	x:Class="ICSharpCode.SharpDevelop.Refactoring.ContextActionsControl"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:s="clr-namespace:System;assembly=mscorlib"
	xmlns:local="clr-namespace:ICSharpCode.SharpDevelop.Refactoring"
	xmlns:aero="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">
	
	<!--The treeview with Context actions. Accepts IEnumerable<ContextActionViewModel> as its DataContext.-->
	
	<UserControl.Resources>
		<Style x:Key="ClearButton" TargetType="Button">
			<Setter Property="FocusVisualStyle" Value="{x:Null}"></Setter>	<!-- Disable the dashed focus rectangle -->
			<Setter Property="Template">
				<Setter.Value>
					<!-- Workaround: TreeViewItem has no Command property.
							To be able to associate actions with TreeViewItems, we use Buttons as content of TreeViewItems. -->
					<ControlTemplate TargetType="Button">
						<Border Name="Border"
						        Padding="2"
						        BorderThickness="1"
						        CornerRadius="1"
						        BorderBrush="Transparent"
						        Background="Transparent">
							<ContentPresenter></ContentPresenter>
						</Border>
						<ControlTemplate.Triggers>
							<Trigger Property="IsMouseOver" Value="True">
								<Setter Property="Background" TargetName="Border" Value="#E8F2FF">
								</Setter>
							</Trigger>
							<Trigger Property="IsFocused" Value="True">
								<Setter Property="Background" TargetName="Border">
									<Setter.Value>
										<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
											<GradientStop Color="#E5F1FF" Offset="0"/>
											<GradientStop Color="#D6E9FF" Offset="0.5"/>
										</LinearGradientBrush>
									</Setter.Value>
									<!--<Setter.Value #A3CEFF darker>
										<DynamicResource ResourceKey="{x:Static SystemColors.HighlightTextBrushKey}" />
									</Setter.Value>-->
								</Setter>
								<Setter Property="BorderBrush" TargetName="Border" Value="#4F7AA8" />
							</Trigger>
						</ControlTemplate.Triggers>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>
	</UserControl.Resources>
	
	
	<TreeView x:Name="TreeView" ItemsSource="{Binding}" BorderThickness="0"
	          Loaded="TreeViewLoaded"
	          ItemTemplate="{Binding Path=ItemTemplate, RelativeSource={RelativeSource AncestorType={x:Type local:ContextActionsControl}}}">
		<TreeView.Background>
			<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
				<GradientStop Color="White"/>
			</LinearGradientBrush>
		</TreeView.Background>
		<TreeView.ItemContainerStyle>
			<Style TargetType="{x:Type TreeViewItem}">
				<Setter Property="Template">
					<Setter.Value>
						<ControlTemplate TargetType="TreeViewItem">
							<StackPanel>
								<!-- ActionButtonClick event is used just to close the Popup -->
								<Button Command="{Binding ActionCommand}" Style="{StaticResource ClearButton}" Click="ActionButtonClick">
									<Border SnapsToDevicePixels="True">
										<ContentPresenter Content="{TemplateBinding HeaderedContentControl.Header}" ContentTemplate="{TemplateBinding HeaderedContentControl.HeaderTemplate}" ContentStringFormat="{TemplateBinding HeaderedItemsControl.HeaderStringFormat}" ContentSource="Header" Name="PART_Header"
											HorizontalAlignment="Stretch" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
									</Border>
								</Button>
								<Border Padding="14 0 0 0">
									<ItemsPresenter Name="ItemsHost"  />
								</Border>
							</StackPanel>
							<ControlTemplate.Triggers>
								<!-- Disable collapsing -->
								<!--<Trigger Property="TreeViewItem.IsExpanded">
										<Setter Property="UIElement.Visibility" TargetName="ItemsHost">
											<Setter.Value>
												<x:Static Member="Visibility.Collapsed" />
											</Setter.Value>
										</Setter>
										<Trigger.Value>
											<s:Boolean>False</s:Boolean>
										</Trigger.Value>
									</Trigger>-->
							</ControlTemplate.Triggers>
						</ControlTemplate>
					</Setter.Value>
				</Setter>
				<!-- Make all items expanded -->
				<Setter Property="IsExpanded" Value="True"></Setter>
				<!-- Make items not focusable so that contained button (not the TreeViewItem) gets focus on Down arrow -->
				<Setter Property="Focusable" Value="False"></Setter>
			</Style>
		</TreeView.ItemContainerStyle>
	</TreeView>

</UserControl>